import time

def read_from_file(filename):
    file = open(filename)
    data = file.readlines()
    data = list(map(int,data))
    return data

m1 = read_from_file('m1_sorted.txt')
m2 = read_from_file('m2_reserve.txt')
m3 = read_from_file('m3_shuffle.txt')

def bubble_sort(a):
    for i in range(len(a)):
        is_sort = True
        for j in range(len(a) - 1):
            if a[j] > a[j + 1]:
                is_sort = False
                a[j], a[j + 1] = a[j + 1], a[j]
        if is_sort:
            return
        
t_start_m1 = time.time()
bubble_sort(m1)
t_finish_m1 = time.time()
time_m1 = round((t_finish_m1 - t_start_m1) * 1000)
print(f'm1_sorted {time_m1} milliseconds')

t_start_m2 = time.time()
bubble_sort(m2)
t_finish_m2 = time.time()
time_m2 = round((t_finish_m2 - t_start_m2) * 1000)
print(f'm2_sorted {time_m2} milliseconds')

t_start_m3 = time.time()
bubble_sort(m3)
t_finish_m3 = time.time()
time_m3 = round((t_finish_m3 - t_start_m3) * 1000)
print(f'm3_sorted {time_m3} milliseconds')
